package com.yuantong.xyerp.core.api.model.base;

import com.yuantong.xyerp.core.api.enums.EnumMsgCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;


/**
 * @author czg
 *
 */
@Getter
public class RestResponseModel<T> {

    @ApiModelProperty("请求是否成功")
    private boolean ok;
    @ApiModelProperty("请求状态码 ：\"0000\", \"ok\"；\"0100\", \"参数异常\" ；\"9999\", \"系统异常，请稍后再试~\"")
    private String code;
    @ApiModelProperty("描述信息")
    private String msg;
    // @ApiModelProperty("")
    // private Object content;
    @ApiModelProperty("返回数据")
    private T data;

    private RestResponseModel(){}

    private RestResponseModel(boolean ok, String code, String msg) {
        this.ok = ok;
        this.code = code;
        this.msg = msg;
    }

    private RestResponseModel(boolean ok, String code, String msg, T data) {
        this.ok = ok;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private RestResponseModel(boolean ok, EnumMsgCode enumMsgCode) {
        this.ok = ok;
        this.code = enumMsgCode.getCode();
        this.msg = enumMsgCode.getMsg();
    }

    // 一般用不到
    private RestResponseModel(boolean ok, EnumMsgCode enumMsgCode, T data) {
        this.ok = ok;
        this.code = enumMsgCode.getCode();
        this.msg = enumMsgCode.getMsg();
        this.data = data;
    }


    public static <T> RestResponseModel<T> SUCCESS(String code, String msg) {
        return new RestResponseModel<>(true, code, msg);
    }

    public static <T> RestResponseModel<T> SUCCESS(String code, String msg, T data) {
        return new RestResponseModel<T>(true, code, msg, data);
    }

    public static <T> RestResponseModel<T> SUCCESS(EnumMsgCode enumMsgCode) {
        return new RestResponseModel<>(true, enumMsgCode);
    }

    public static <T> RestResponseModel<T> SUCCESS(EnumMsgCode enumMsgCode, T data) {
        return new RestResponseModel<T>(true, enumMsgCode, data);
    }


    public static <T> RestResponseModel<T> FAIL(String code, String msg) {
        return new RestResponseModel<>(false, code, msg);
    }

    public static <T> RestResponseModel<T> FAIL(String code, String msg, T data) {
        return new RestResponseModel<T>(false, code, msg, data);
    }

    public static <T> RestResponseModel<T> FAIL(EnumMsgCode enumMsgCode) {
        return new RestResponseModel<>(false, enumMsgCode);
    }

    public static <T> RestResponseModel<T> FAIL(EnumMsgCode enumMsgCode, T data) {
        return new RestResponseModel<T>(false, enumMsgCode, data);
    }

}
